﻿<?php
// ------------------------------------------------------------------
// NEEDED STUBS FOR THIS EXAMPLE
// ------------------------------------------------------------------


// this will include all needed files to be able to build a Request
include_once($CONF["STUBS_FOLDER"]."Map24LocationService/Map24LocationService.php5");


// ------------------------------------------------------------------
// NEEDED PARAMETERS FOR THIS REQUEST
// ------------------------------------------------------------------


$Offset = 0;
$Count = 20;
$MaxNoOfGeocodeAlternatives = 5;
$Radius = 1000;

// definition of the layers we search for
$LayerID='10|15';

// you can also define customerLayers
// avalible customerLayers: 7779|7778|7780|3509|3510|3511|3512|73|6926|74|75|76|77|5571|5572|5570|7779|7778|7780|6926|5362|8395|8398|8405|8396|8397|8402|8394|8401|8404|8399|8403|8400|7324|3563|5902|5900|5901|5621|9236|9121|9237|9120|9122|8992|8990|8991|3767|5606|5607|5636|5761|5997|7361|7362|7363|5571|5572|5570
//$CustomerLayerID='';


// definition of the Points

// define a Point by Address
$pIdx=0;
$Points[$pIdx]=new CoordinateAndAddress();
$Points[$pIdx]->Address= new Address();
$Points[$pIdx]->Address->Street = "Goethestr.";
$Points[$pIdx]->Address->City = "Frankfurt";
$Points[$pIdx]->Address->ZIP = "60311";
$Points[$pIdx]->Address->Country = "de";

// define another Point by Address
$pIdx++;
$Points[$pIdx]=new CoordinateAndAddress();
$Points[$pIdx]->Address= new Address();
$Points[$pIdx]->Address->Street = "Duesseldorfer-Str.";
$Points[$pIdx]->Address->City = "Eschborn";
$Points[$pIdx]->Address->ZIP = "65760";
$Points[$pIdx]->Address->Country = "de";

// alternative define a Point by Coordinates
$pIdx++;
$Points[$pIdx]=new CoordinateAndAddress();
$Points[$pIdx]->Coordinate= new Coordinate();
$Points[$pIdx]->Coordinate->Longitude="521.0196";
$Points[$pIdx]->Coordinate->Latitude="3006.554";




// ------------------------------------------------------------------
// BUILDING THE REQUEST
// ------------------------------------------------------------------


// definition of the request header with Map24ID and SessionID
$header = new RequestHeader();
$header->Map24ID  = $CONF['MAP24_ID'];
$header->ClientID = $CONF['SESSION_ID'];

// definition of the request body
$request= new FindByPointsRequest();
$request->Points=$Points;
$request->Offset = $Offset;
$request->Count = $Count;
$request->Radius = $Radius;
$request->Map24LayerIDs=array($LayerID);
//$request->CustomerLayerIDs=array($CustomerLayerID);
$request->MaxNoOfGeocodeAlternatives=$MaxNoOfGeocodeAlternatives;



// ------------------------------------------------------------------
// EXECUTE THE REQUEST
// ------------------------------------------------------------------


// in this object the SoapClient will be initiated and executed
$maploc = new Map24LocationService($CONF['MAPTP_SYSTEM'],$CONF['MAP24_ID'],$CONF['SESSION_ID']);
$response = $maploc->findByPoints($header,$request);


// ------------------------------------------------------------------
// OUTPUT THE RESULT
// ------------------------------------------------------------------


//counter for points
$pointNo=0;

if( isset($response->Addresses) )
{
	foreach ($response->Addresses as $points) {
		$pointNo++;
		$resultString.= "<p><div style='border:1px solid black;margin:2px 0px;padding:5px;'>";
		$resultString.="<b> [counter] Results for point No. " . $pointNo . "</b><br/><br/>";
		if(isset( $points->Alternatives[0]->Street) ) {$resultString.= $points->Alternatives[0]->Street . "<br/>"; }
		if(isset( $points->Alternatives[0]->ZIP) ) {$resultString.= $points->Alternatives[0]->ZIP ."&nbsp;" . $points->Alternatives[0]->City . "<br/>"; }
		if(isset( $points->Alternatives[0]->State) ) {$resultString.= $points->Alternatives[0]->State ."<br/>"; }
		if(isset( $points->Alternatives[0]->Coordinate) ) {$resultString.= $points->Alternatives[0]->Coordinate->Longitude ."<br/>". $points->Alternatives[0]->Coordinate->Latitude ."<br/><br/><br/>"; }


		foreach ($points->Map24Locations as $result)
		{
			$counter++;
			$resultString .= "<div style='border:1px solid black;margin:2px 0px;padding:5px;'>".$counter.". ";
			$resultString .= "<img src='http://img.map24.com/map24/portal/symbols/poi_" . $result->SymbolID . ".png'>&nbsp;<b>" . $result->Name1 . "</b><br /><br />";
			$resultString .= "LayerID: " . $result->LayerID . "<br />";
			$resultString .= "LocationID: " . $result->LocationID . "<br />";
			$resultString .= "Street: " . $result->Street . "<br />";
			$resultString .= "ZIP, City: " . $result->ZIP . "&nbsp;" . $result->City . "<br /><br />";
			$resultString .= "Distance: " . $result->Distance . "<br /><br />";
			$resultString .= "</div>";
		}
		$resultString.="</div></p>";
		$resultString = str_replace("[counter]",$counter,$resultString);
		$counter=0;
	}
}
else {
	$resultString = "Sorry, nothing found. Please try a other layer or a bigger radius";
}

?>